<!DOCTYPE html>
<html lang="zh_CN">
<head>
<#assign currentMenu="store"/>
    <#include "../common/header.ftl">
    <script src="/js/plugins/jquery-bootstrap/jquery.bootstrap.min.js"></script>
</head>
<body>

<div class="container " style="margin-top: 20px">
<#include "../common/top.ftl">
    <div class="row">
        <div class="col-lg-3">
        <#include "../common/menu.ftl">
        </div>
        <div class="col-lg-9">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-head-line">商品管理</h1>
                </div>
            </div>
            <!--高级查询-->
            <form class="form-inline" id="searchForm" action="/store/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>商品搜索:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入商品名称">
                </div>
                <button class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a role="button" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 新增
                </a>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>序号</th>
                    <th>商品名称</th>
                    <th>商品简介</th>
                    <th>商品图片</th>
                    <th>所需积分</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            <#list pageInfo.list as entity>
                <tr>
                    <td>${entity_index + 1}</td>
                    <td>${entity.name}</td>
                    <td>${entity.introduce}</td>
                    <td><img src="${(entity.coverUrl)!}" width="80px"></td>
                    <td>${entity.score}</td>
                    <td>${entity.stateName}</td>
                    <td>

                        <a role="button" class="btn btn-info btn-xs inputBtn" data-json='${entity.json}'>
                            <span class="glyphicon glyphicon-pencil"></span> 修改
                        </a>

                        <a href="javascript:;" class="btn btn-danger btn-xs deleteBtn" data-url="/store/delete.do?id=${entity.id}" >
                            <span class="glyphicon glyphicon-trash"></span> 删除
                        </a>
                    </td>
                </tr>
            </#list>
            </table>
        <#include "../common/page.ftl">
        </div>
    </div>
</div>


<div class="modal fade" id="storeModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">积分商品新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/store/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" id="storeId" name="id">
                    <div class="form-group">
                        <label for="name" class="col-sm-4 control-label">商品名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="name" name="name">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="name" class="col-sm-4 control-label">商品简介：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="introduce" name="introduce">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-lg-4 control-label">商品封面：</label>
                        <div class="col-lg-6">
                            <img id="coverUrl" style="width: 100%"/>
                            <input type="file" class="form-control" name="img" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="name" class="col-sm-4 control-label">所需积分：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="score" name="score">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="state" class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select class="form-control" autocomplete="off" name="state" id="state">
                                <option value="0">下架</option>
                                <option value="1">上架</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-success submitBtn">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->




<script>
    $(function () {
        $(".inputBtn").click(function () {
            $("#editForm input").val("");
            $("#coverUrl").attr("src", "");

            //处理修改时的数据回显
            var json = $(this).data("json");
            if (json) {
                $("#editForm input[name='id']").val(json.id);
                $("#editForm input[name='name']").val(json.name);
                $("#editForm input[name='introduce']").val(json.introduce);
                $("#coverUrl").attr("src", json.coverUrl);
                $("#editForm input[name='score']").val(json.score);
                $("#editForm select[name='state']").val(json.state);
            }

            $("#storeModal").modal("show");
        });



        $(".submitBtn").click(function () {
            $("#editForm").submit();
        });
    })
</script>

</body>
</html>